<?php
#
# dmBridge: a data access framework for CONTENTdm(R)
#
# Copyright © 2009, 2010 Board of Regents of the Nevada System of Higher
# Education, on behalf of the University of Nevada, Las Vegas
#

/**
 * @author Alex Dolski <alex.dolski@unlv.edu>
 * @license http://www.opensource.org/licenses/mit-license.php
 */
class DMException extends Exception implements DMLoggable {

	/** @var boolean */
	private $has_been_logged;

	/** @var unsigned int */
	private $http_response_code = 500;

	/**
	 * @param string msg
	 * @param int code
	 * @since 0.1
	 */
	public function __construct($msg = null, $code = 2) {
		ini_set('xdebug.remote_mode', 'jit');
		parent::__construct($msg, $code);
	}

	/**
	 * @return Boolean
	 * @since 0.1
	 */
	public final function hasBeenLogged() {
		return $this->has_been_logged;
	}

	/**
	 * @param bool bool
	 */
	public final function setHasBeenLogged($bool) {
		$this->has_been_logged = ($bool);
	}

	/**
	 * @return int
	 */
	public final function getHTTPResponseCode() {
		return $this->http_response_code;
	}

	/**
	 * If the exception is to be presented publicly, it should have a useful
	 * HTTP status code set. Some exceptions are handled internally in which
	 * case this doesn't matter.
	 *
	 * @param int int
	 */
	public final function setHTTPResponseCode($int) {
		$this->http_response_code = $int;
	}

	/**
	 * Wraps getMessage() in order to comply with DMLoggable.
	 *
	 * @return string
	 */
	public final function getLogMessage() {
		return $this->getMessage();
	}

	/**
	 * Wraps getCode().
	 *
	 * @return int
	 */
	public final function getLogPriority() {
		return $this->getCode();
	}

	/**
	 * Wraps setCode().
	 *
	 * @param int
	 */
	public function setLogPriority($int) {
		$this->setCode($int);
	}

}
